package work.mediway.mdm.runner;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;

import java.net.InetAddress;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2020/1/21
 */
@Slf4j
@Component
public class MdmStartedUpRunner implements ApplicationRunner {

    private ConfigurableApplicationContext context;

    @Autowired
    public MdmStartedUpRunner(ConfigurableApplicationContext context) {
        this.context = context;
    }

    @Value("${server.port:8080}")
    private String port;
    @Value("${server.servlet.context-path:}")
    private String contextPath;


    @Override
    public void run(ApplicationArguments args) throws Exception {
        if (context.isActive()) {
            InetAddress address = InetAddress.getLocalHost();
            String url = String.format("http://%s:%s", address.getHostAddress(), port);
            if (StringUtils.isNotBlank(contextPath)) {
                url += contextPath;
            }
            log.info(",--.   ,--.          ,--.,--.              ,--.       ,--.   ,--.,------.  ,--.   ,--. ");
            log.info("|   `.'   | ,---.  ,-|  |`--' ,---. ,--,--.|  |,-----.|   `.'   ||  .-.  \\ |   `.'   | ");
            log.info("|  |'.'|  || .-. :' .-. |,--.| .--'' ,-.  ||  |'-----'|  |'.'|  ||  |  \\  :|  |'.'|  | ");
            log.info("|  |   |  |\\   --.\\ `-' ||  |\\ `--.\\ '-'  ||  |       |  |   |  ||  '--'  /|  |   |  |");
            log.info("`--'   `--' `----' `---' `--' `---' `--`--'`--'       `--'   `--'`-------' `--'   `--' ");
            log.info("DIMPLES 权限系统启动完毕，地址：{}", url);
            log.info("DIMPLES webservice，地址：{}", StrUtil.removeSuffix(url, "/") + "/webservice");
            log.info("DIMPLES 文档地址：{}", StrUtil.removeSuffix(url, "/") + "/doc.html");
            log.info("============= 主数据启动成功 =============");
        }
    }
}

















